package org.sxm.cloud.controller;

import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.sxm.cloud.dto.pay.PayDTO;
import org.sxm.cloud.entity.pay.PayEntity;
import org.sxm.cloud.service.IPayService;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @Description
 * @Author xmSheng
 * @Date 2024/1/30
 */
@RefreshScope //Nacos动态刷新配置
@RestController
public class PayController {

    @Resource
    private IPayService payService;

    /**
     * 模拟订单支付
     *
     * @param payDTO 支付详情
     * @return
     */
    @PostMapping("/pay")
    public int pay(@RequestBody PayDTO payDTO) {
        PayEntity payEntity = new PayEntity();
        payEntity.setPayPrice(payDTO.getPayPrice());
        payEntity.setCreateTime(new Date());
        payEntity.setPayUserId(payDTO.getPayUserId());
        payEntity.setOrderId(payDTO.getOrderId());
        payEntity.setPayeeUserId(payDTO.getPayeeUserId());
        return payService.pay(payEntity);
    }
}
